﻿namespace EFS.RC.SupervisorCentral.Controls
{
	/// <summary>
	/// Interaction logic for FilterPhones.xaml
	/// </summary>
	public partial class FilterPhones : System.Windows.Window
	{
		public FilterPhones(System.Collections.Generic.IEnumerable<System.String> availablePhones = null)
		{
			InitializeComponent();

			// load frmom available
			if (null != availablePhones)
			{
				// filter phones
				System.String filterPhonesValue = EFS.RC.SupervisorCentral.Common.Config.AppSettings.FilterPhones;

				foreach (System.String phone in availablePhones)
				{
					if (!EFS.Common.Verify.String(filterPhonesValue) || filterPhonesValue.IndexOf(phone) >= 0)
					{
						listBoxFilter.Items.Add(phone);
					}
					else
					{
						listBoxPhones.Items.Add(phone);
					}
				}
			}
		}

		private void buttonAdd_Click(object sender, System.Windows.RoutedEventArgs e)
		{
			if (null != listBoxPhones.SelectedItem)
			{
				listBoxFilter.Items.Add(listBoxPhones.SelectedItem);
				listBoxPhones.Items.Remove(listBoxPhones.SelectedItem);
			}
		}

		private void buttonRemove_Click(object sender, System.Windows.RoutedEventArgs e)
		{
			if (null != listBoxFilter.SelectedItem)
			{
				listBoxPhones.Items.Add(listBoxFilter.SelectedItem);
				listBoxFilter.Items.Remove(listBoxFilter.SelectedItem);
			}
		}

		private void buttonClose_Click(object sender, System.Windows.RoutedEventArgs e)
		{
			System.Text.StringBuilder sb = new System.Text.StringBuilder();
			foreach (System.String item in listBoxFilter.Items)
			{
				if (EFS.Common.Verify.String(item))
				{
					sb.AppendFormat("{0};", item);
				}
			}
			EFS.RC.SupervisorCentral.Common.Config.AppSettings.FilterPhones = sb.ToString();
			Close();
		}
	}

}